package com.tmsb.utils.aggfunctions;

import com.tmsb.pojo.OrderGoods;
import java.math.BigDecimal;
import org.apache.flink.api.common.functions.AggregateFunction;

/**
 *Description:
 *Version:1.0.0
 *@author shihb
 *@date 2020/6/11 18:19
 */
public class SumAgg<IN> implements AggregateFunction<IN, Double, Double> {
  @Override
  public Double createAccumulator() {
    return 0D;
  }

  @Override
  public Double add(IN in, Double acc) {
    Double sum = 0D;
    if(OrderGoods.class.isInstance(in)){
      OrderGoods og=(OrderGoods)in;
      BigDecimal a = new BigDecimal(acc);
      BigDecimal b = new BigDecimal(og.getPay_price());
      sum=a.add(b).doubleValue();
    }
    return sum;
  }

  @Override
  public Double getResult(Double acc) {
    return acc;
  }

  @Override
  public Double merge(Double acc, Double acc1) {
    BigDecimal a = new BigDecimal(acc);
    BigDecimal b = new BigDecimal(acc1);
    return a.add(b).doubleValue();
  }
}
